package main

import (
	"fmt"
	"io"
	"os"
)

func main() {
	sourceFile, err := os.Open("G:\\workspace_gitee\\golang\\golang-web\\test\\file.txt")

	if err != nil {
		fmt.Println("Error:", err)
		return
	}
	defer sourceFile.Close()
	destFile, err := os.Create("G:\\workspace_gitee\\golang\\golang-web\\test\\destinatior.txt")
	if err != nil {
		fmt.Println("Error:", err)
		return
	}
	defer destFile.Close()

	buffer := make([]byte, 4096) // 适当大小的读取缓冲区
	for {
		n, err := sourceFile.Read(buffer)
		if err != nil && err != io.EOF {
			fmt.Println("Error:", err)
			return
		}
		fmt.Println("n:", n)
		if n == 0 {
			break
		}
		_, err = destFile.Write(buffer[:n])
		if err != nil {
			fmt.Println("Error:", err)
			return
		}
	}
	fmt.Println("File copied successfully.")
}
